﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Quizgame
{
    class Class1
    {
        public SqlConnection KetNoi()
        {
            return new SqlConnection(@"Data Source=localhost;Initial Catalog=Quiz;Integrated Security=True"); //Giao thức kết nối vào SQLEXPRESS
        }
        public bool Dangnhap(string s1, string s2)
        {
            SqlConnection con = KetNoi();
            string sql =
                "SELECT ID, Score " +
                "FROM TAIKHOAN " +
                "WHERE ID = '" + s1 + "' " +
                "AND Score = '" + s2 + "'";
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                con.Close();
                return true;
            }
            else
            {
                con.Close();
                return false;
            }  
        }
        public void Dangky(string s1,string s2)
        {
            SqlConnection con = KetNoi();
            string sql =
                "INSERT TAIKHOAN(ID, Score) " +
                "VALUES ('" + s1 + "','" + s2 + "')";
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.ExecuteNonQuery();
        }

        public string Get(string select, string where, string dk)
        {
            SqlConnection con = KetNoi();
            string sql =
                "SELECT " + select + " " +
                "FROM TAIKHOAN " +
                "WHERE " + where + " = '" + dk + "'";
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            return (string)cmd.ExecuteScalar();
        }
    
    }
}
